#include <QGuiApplication>
#include <QtQml> // for type QQmlContext
#include <QtGui> // for Sleep()
#include <QQmlApplicationEngine>
#include <QTime>

class CurrentTime {
public:
    QString value() { return QTime::currentTime().toString(); }
};

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    CurrentTime current;
    QQmlApplicationEngine engine;

    const QUrl url(u"qrc:/chapter18-1SetContextProperty/Main.qml"_qs);

#if 0
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
        &app, []() { QCoreApplication::exit(-1); },
        Qt::QueuedConnection);
#endif

    engine.rootContext()->setContextProperty("current", current.value());
    engine.load(url);
    Sleep(2000);
    engine.rootContext()->setContextProperty("current", current.value());

    return app.exec();
}
